package kr.hkit.powerjava.chapter24.submit3;

import java.util.Comparator;
import java.util.Scanner;


public class DepartmentService_Service extends ServiceItem_Service<Department_Vo> {

	public DepartmentService_Service(Interface_Dao<Department_Vo> dao,
			Scanner sc) {
		super(dao, sc);
	}
	
	@Override
	public Department_Vo inputItemInfo(boolean gubun) {
		System.out.println("학과번호 학과명"); 
		Department_Vo dept = new Department_Vo(sc.nextInt(), sc.next().trim());
		
		if (gubun) {			
			System.out.println("위치(층)");
			dept.setFloor(sc.nextInt());
		}
		return dept;
	}

	@Override
	public void prnSubMenu() { //정렬
		int res = 0; 
		System.out.println("1.학과명순 정렬 2.위치별 정렬 3.학과번호순 정렬");
		res = sc.nextInt();
		
		switch(res) {
			case 1:
				dao.prnItem(new Comparator<Department_Vo>() { //학과명순 정렬
					@Override
					public int compare(Department_Vo o1, Department_Vo o2) {
						return o1.getDeptName().hashCode() - o2.getDeptName().hashCode();
					}
				});
				break;
				
			case 2:
				dao.prnItem(new Comparator<Department_Vo>() { //위치별 정렬
					@Override
					public int compare(Department_Vo o1, Department_Vo o2) {
						return o1.getFloor() - o2.getFloor();
					}
				});
				break;
				
			default:
				dao.prnItem(null); //기본 학과번호순 정렬
				break;
		}
	}
}
